package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.annotation.Log;
import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.domain.model.LoginUser;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.enums.BusinessType;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.framework.web.service.TokenService;
import com.zhuoyue.system.domain.TblGatewayZy;
import com.zhuoyue.system.service.ITblGatewayZyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * gatewayZYController
 *
 * @author hewenze
 * @date 2020-09-08
 */
@RestController
@RequestMapping("/system/gatewayZY")
public class TblGatewayZyController extends BaseController {
    @Autowired
    private ITblGatewayZyService tblGatewayZyService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询gatewayZY列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TblGatewayZy tblGatewayZy) {
        startPage();
        List<TblGatewayZy> list = tblGatewayZyService.selectTblGatewayZyList(tblGatewayZy);
        return getDataTable(list);
    }

    /**
     * 导出gatewayZY列表
     */
    @Log(title = "gatewayZY", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TblGatewayZy tblGatewayZy) {
        List<TblGatewayZy> list = tblGatewayZyService.selectTblGatewayZyList(tblGatewayZy);
        ExcelUtil<TblGatewayZy> util = new ExcelUtil<TblGatewayZy>(TblGatewayZy.class);
        return util.exportExcel(list, "gatewayZY");
    }

    /**
     * 获取gatewayZY详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tblGatewayZyService.selectTblGatewayZyById(id));
    }

    /**
     * 新增gatewayZY
     */
    @Log(title = "gatewayZY", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TblGatewayZy tblGatewayZy, HttpServletRequest request) {
        LoginUser loginUser = tokenService.getLoginUser(request);
        tblGatewayZy.setCreateBy(loginUser.getUsername());
        return toAjax(tblGatewayZyService.insertTblGatewayZy(tblGatewayZy));
    }

    /**
     * 修改gatewayZY
     */
    @Log(title = "gatewayZY", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TblGatewayZy tblGatewayZy) {
        return toAjax(tblGatewayZyService.updateTblGatewayZy(tblGatewayZy));
    }

    /**
     * 删除gatewayZY
     */
    @Log(title = "gatewayZY", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tblGatewayZyService.deleteTblGatewayZyByIds(ids));
    }
}
